package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.R;
import com.example.shixunandjavagotoyangchen.Sunshine.FragmentSpaek.FragmentSpaek2;
import com.google.android.material.tabs.TabLayout;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import java.util.ArrayList;

import io.reactivex.annotations.Nullable;
public class BlankFragmentDay001 extends BasterFragment {

    private TabLayout makeWokaTale;
    public static ViewPager makeWokaView;
    private ImageView makeSaomiao;
    private TextView makeSousuo;
    private ImageView makeXiaoxi;


    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day001;
    }

    @Override
    public void initView() {

        makeWokaTale = (TabLayout) findViewById(R.id.make_wokaTale);
        makeWokaView = (ViewPager) findViewById(R.id.make_wokaView);
        makeSaomiao = (ImageView) findViewById(R.id.make_saomiao);
        makeSousuo = (TextView) findViewById(R.id.make_sousuo);
        makeXiaoxi = (ImageView) findViewById(R.id.make_xiaoxi);
    }

    @Override
    public void initDate() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.CAMERA,Manifest.permission.VIBRATE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 200);
        }
        makeSaomiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sao();
            }
        });

        makeXiaoxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("xiaoxi:","消息");
                ARouter.getInstance().build("/xiao/xi").navigation();
            }
        });

        makeSousuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("xiaoxi:","搜索");
                ARouter.getInstance().build("/sou/suo").navigation();
            }
        });


        //数据
        ArrayList<Fragment> day1fragment = new ArrayList<>();
        ArrayList<String> day1string = new ArrayList<>();

        day1fragment.add(new BlankFragmentDay00101());
        day1fragment.add(new BlankFragmentDay00102());
        day1fragment.add(new BlankFragmentDay00103());
        day1fragment.add(new BlankFragmentDay00104());
        day1fragment.add(new BlankFragmentDay00105());
        day1fragment.add(new BlankFragmentDay00106());
        day1fragment.add(new BlankFragmentDay00107());
        day1fragment.add(new BlankFragmentDay00108());

        day1string.add("有货");
        day1string.add("上装");
        day1string.add("裤装");
        day1string.add("球鞋");
        day1string.add("女装");
        day1string.add("生活");
        day1string.add("潮玩");
        day1string.add("美妆");

        FragmentSpaek2 list = new FragmentSpaek2(getActivity().getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, day1fragment, day1string);
        makeWokaView.setAdapter(list);
        makeWokaTale.setupWithViewPager(makeWokaView);
        makeWokaTale.setSelectedTabIndicatorHeight(0);//取消指示器

        makeWokaTale.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //选中第一个
                TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.tab_item_text, null);
                textView.setTextSize(20);
                textView.setText(tab.getText());
                tab.setCustomView(textView);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }


    //----------------------------------------扫描二维码-----------------------------------
    private void sao() {
        Intent intent = new Intent(getActivity(), CaptureActivity.class);
        startActivityForResult(intent,550);
    }

    //处理结果
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 550 && resultCode == Activity.RESULT_OK && data != null) {
            Bundle bundle = data.getExtras();
            if (bundle == null) {
                return;
            }
            if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                String string = bundle.getString(CodeUtils.RESULT_STRING);
                Toast.makeText(getActivity(), "扫描结果" + string, Toast.LENGTH_SHORT).show();
            }
        }

    }
    //--------------------------------------------------------------------------------------






}
